package com.achen.controller;

import com.achen.dao.CardbscDao;
import com.achen.entity.Result;
import com.achen.pojo.Cardbsc;
import com.achen.service.CardbscService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author limeng
 * @create 2021-06-28 15:20
 */
@RestController
@Slf4j
public class CardbscController {

    @Autowired
    private CardbscService cardbscService;

    @Autowired
    private CardbscDao cardbscDao;


    @GetMapping("/cardbsc/findByCardnoAndPassword")
    @CrossOrigin(origins = "*",maxAge = 3600)
    public Result findByCardnoAndPassword(@RequestParam("cardno") String cardno, @RequestParam("password") String password) {
        log.info("cardno:[{}]", cardno);
        log.info("password:[{}]", password);
        Cardbsc cardbsc = null;
        try {
            cardbsc = cardbscDao.findByCardnoAndPassword(cardno, password);
            log.info("cardbsc:[{}]", cardbsc.toString());
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(201, cardbsc, "查询失败");
        }
        return new Result(200, cardbsc, "查询成功");
    }

    @GetMapping("/cardbsc/findAll")
    public List<Cardbsc> findAll() {
        String str = this.getStr();
        System.out.println(str);
        System.out.println(222);
        System.out.println(111);
        return cardbscService.findAll();
    }

    public String getStr() {
        return "ok";
    }
}
